package daobeauty.interceptor.returntype.executor.query;

import org.hibernate.Query;

import daobeauty.dao.Limiting;
import daobeauty.interceptor.returntype.handler.ReturnTypeHandler;

public class UniqueResultQueryExecutionStrategy implements QueryExecutionStrategy {
	public static final UniqueResultQueryExecutionStrategy INSTANCE = new UniqueResultQueryExecutionStrategy();
	
	public Object execute(ReturnTypeHandler returnTypeHandler, Query query, Limiting limiting) {
		query.setMaxResults(1);
		if (limiting!=null){
			query.setFirstResult(limiting.getOffset());
		}
		return returnTypeHandler.convert(query.uniqueResult());
	}
}
